#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
typedef pair<LL,LL>P;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn],dis[maxn];
bool vis[maxn];
struct Edge{
    LL to,cost;
};
vector<Edge>g[maxn];
void dijkstra(LL s){
    memset(dis,0x3f,sizeof(dis));
    LL st=s;
    dis[st]=0;
    priority_queue< P, vector<P> ,greater<P> >que;
    que.push({dis[st],st});
    while(!que.empty()){
        P now=que.top();que.pop();
        LL u=now.second;
        if(vis[u]) continue;
        vis[u]=true;
        for(LL i=0;i<g[u].size();i++){
            Edge e=g[u][i];
            LL to=e.to;LL cost=e.cost;
            if(dis[to]>dis[u]+cost){
                dis[to]=dis[u]+cost;
                dp[to]=dp[u]%mod;
                que.push({dis[to],to});
            }
            else if(dis[to]==dis[u]+cost){
                dp[to]=(dp[to]%mod+dp[u]%mod)%mod;
            }
        }
    }
}
int main(void)
{
    LL n,m;
    n=read();m=read();
    dp[1]=1;
    for(LL i=1;i<=m;i++){
        LL u,v,cost;cin>>u>>v;
        cost=1;
        g[u].push_back({v,cost});
        g[v].push_back({u,cost});
    }
    dijkstra(1);
    if(dis[n]==0x3f3f3f3f3f3f3f3f){
        cout<<"0"<<"\n";
    }
    else cout<<dp[n]<<"\n";
return 0;
}
